import {
    Entity,
    PrimaryGeneratedColumn,
    Column,
    CreateDateColumn,
    UpdateDateColumn,
    ManyToOne,
    JoinColumn
} from 'typeorm';
import { User } from '../../users/entities/user.entity';

export type AssetType = 'solar' | 'charging' | 'real_estate' | 'infrastructure' | 'other';
export type AssetStatus = 'draft' | 'pending' | 'approved' | 'rejected' | 'tokenized';

@Entity('assets')
export class Asset {
    @PrimaryGeneratedColumn()
    id: number;

    @Column()
    name: string;

    @Column({ type: 'text', nullable: true })
    description?: string;

    @Column({ type: 'enum', enum: ['solar', 'charging', 'real_estate', 'infrastructure', 'other'] })
    type: AssetType;

    @Column({ nullable: true })
    location?: string;

    @Column({ type: 'decimal', precision: 20, scale: 8, default: 0 })
    totalValue: string;

    @Column({ type: 'decimal', precision: 20, scale: 8, default: 0 })
    tokenizedValue: string;

    @Column({ type: 'enum', enum: ['draft', 'pending', 'approved', 'rejected', 'tokenized'], default: 'draft' })
    status: AssetStatus;

    @Column({ nullable: true })
    nftContract?: string;

    @Column({ nullable: true })
    erc20Contract?: string;

    @Column({ type: 'int', nullable: true })
    nftTokenId?: number;

    @ManyToOne(() => User, { eager: true })
    @JoinColumn({ name: 'owner_id' })
    owner: User;

    @CreateDateColumn()
    createdAt: Date;

    @UpdateDateColumn()
    updatedAt: Date;
}
